import { GameEvent } from "../GameEvent";
import { BaseView } from "../ui_view/base/BaseView";

const bestScoreLabelContent: string = 'Best Score:';
const currentScoreLabelContent: string = 'Current Score:';
export class FinishView extends BaseView{
    private bestScoreLabel: cc.Label;
    private currentScoreLabel: cc.Label;
    private replayBtn: cc.Button;
    private currentScore: number;
    private bestScore: number;

    public constructor(node: cc.Node){
        super(node);
        this.bestScoreLabel = cc.find('game/finish_view/best_score').getComponent(cc.Label);
        this.currentScoreLabel = cc.find('game/finish_view/player_score').getComponent(cc.Label);
        this.replayBtn = cc.find('game/finish_view/btn_play').getComponent(cc.Button);
        this.replayBtn.node.on('click', this.onReplayBtnClick, this);
    }

    public setData(currentScore: number, bestScore: number): void{
        this.currentScore = currentScore;
        this.bestScore = bestScore;
    }

    public show(): void {
        super.show();
        this.currentScoreLabel.string = currentScoreLabelContent + this.currentScore.toString();
        this.bestScoreLabel.string = bestScoreLabelContent + this.bestScore.toString();
    }

    private onReplayBtnClick(){
        console.log('点击重玩按钮');
        GameEvent.OnReplayGame();
    }
}